import 'package:common/base/base_state.dart';
import 'package:common/base/base_stateful_widget.dart';
import 'package:flutter/material.dart';

import '../model/multi_select_list_bean.dart';
import 'group_page.dart';

/**
 * https://blog.csdn.net/weixin_52262025/article/details/123753879
 */
class DragLayoutPage extends BaseStatefulWidget {
  const DragLayoutPage({super.key});

  @override
  State<DragLayoutPage> createState() => _DragLayoutPageState();
}

class _DragLayoutPageState extends BaseState<DragLayoutPage> {

  @override
  void onStateInit() {
  }

  @override
  bool onNeedAppBar() {
    return false;
  }

  @override
  Widget onBodyCreate() {
    return Stack(children: [
      const Center(child: Text("这是一个运动布局")),
      _buildDraggableScrollableSheet()
    ]);
  }

  Widget _buildDraggableScrollableSheet() {
    return DraggableScrollableSheet(
    //初始化占用父容器高度
    initialChildSize: 0.25,
    //占用父组件的最小高度
    minChildSize: 0.25,
    //占用父组件的最大高度
    maxChildSize: 1,
    //是否应扩展以填充其父级中的可用空间默认true 父组件是Center时设置为false,才会实现center布局，但滚动效果是向两边展开
    expand: true,
    //true：触发滚动则滚动到maxChildSize或者minChildSize，不在跟随手势滚动距离 false:滚动跟随手势滚动距离
    snap: true,
    // 当snapSizes接收的是一个数组[],数组内的数字必须是升序，而且取值范围必须在 minChildSize,maxChildSize之间
    //作用是可以控制每次滚动部件占父容器的高度，此时expand: true,
    snapSizes: const [0.4, 1],
    builder: (BuildContext context, ScrollController scrollController) {
      return GroupPage(scrollController:scrollController);
    },
    );
  }


  @override
  void onSuccess<D>(D d, String apiPath) {
    super.onSuccess(d, apiPath);
    if (d is MultiSelectListBean) {
      MultiSelectListBean bean = d;
    }
  }
}
